package chapter4.lessons;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.ThreadPoolExecutor;

/**
 * @Project ：learn_java
 * @File ：MyThreadPoolDemo02.java
 * @IDE ：IntelliJ IDEA
 * @Author ：自由如风间
 * @Date ：2025/3/7 16:01
 * @Description ：创建指定线程数量的线程池。
 */

public class MyThreadPoolDemo02 {
    public static void main(String[] args) {
        // 创建一个指定最多线程数量的线程池。
        // 这里的参数不是初始化值，而是最大值
        ExecutorService executorService = Executors.newFixedThreadPool(5);

        ThreadPoolExecutor pool = (ThreadPoolExecutor) executorService;
        System.out.println(pool.getPoolSize());

        executorService.submit(
                ()-> System.out.println(Thread.currentThread().getName() + "正在执行")
        );

        executorService.submit(
                ()-> System.out.println(Thread.currentThread().getName() + "正在执行")
        );

        System.out.println(pool.getPoolSize());
        executorService.shutdown();
    }
}
